package com.bjpowernode.springboot.web;

import com.bjpowernode.springboot.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Scanner;

//@Controller
@RestController//相当于控制层类上加@Controller + 方法上加@ResponseBody,意味着当前控制层所有方法返回的都是JSON对象
public class StudentController {
    @RequestMapping(value = "/student")
    //@ResponseBody
    public Object student(){
        Student student = new Student();
        student.setName("任子艺");
        student.setId(3);
        return student;
    }

    //该方法支持get和post请求方式
    @RequestMapping(value = "/studentDetail",method = {RequestMethod.GET,RequestMethod.POST})
    public Object queryStudentById(Integer id){
        Student student = new Student();
        student.setId(id);
        return student;
    }

    //@RequestMapping(value = "queryStudent",method = RequestMethod.GET)
    @GetMapping(value = "queryStudent")//相当于上一句话，只接受get请求，如果请求方式不对会包405错误
    //该注解通过在查询数据的时候使用 ->查询
    public  Object queryStudentById2(){
        return "Only GET Method";
    }

    //@RequestMapping(value = "/insert",method = RequestMethod.POST)
    @PostMapping(value = "/insert")//相当于上一句话
    //该注解通常在新增数据的时候使用 ->新增
    public Object insert(){
        return "Insert success";
    }

    //@RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @DeleteMapping(value = "/delete")//相当于上一句话
    //该注解通常在删除数据的使用 ->删除
    public Object delete(){
        return "delete Student";
    }

    //@RequestMapping(value = "/update",method = RequestMethod.PUT)
    @PutMapping(value = "/update") //相当于上一句话
    //该注解通常在修改数据的使用 -> 更新
    public Object update(){
        return "update student information";
    }


}
